import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Demo01 {
    /*
    1.创建一个学生数组，学生里面有 id name address age 这些属性。
    创建5个学生放入。 要求如下：
    1.统计学生有多少是湖北的。
    2.将年龄大于18的同学找出来。不能光打印，需要存储下来，
    3.统计一下名字中包含 z 的且年龄大于18的,存储下来。
     */
    public static void main(String[] args) {
        ArrayList<Student123> list = new ArrayList<>();
        list.add(new Student123(1, "zs", "湖北", 18));
        list.add(new Student123(2, "ls", "湖北", 23));
        list.add(new Student123(3, "ww", "湖北", 22));
        list.add(new Student123(4, "zl", "安徽", 15));
        list.add(new Student123(5, "xq", "北京", 14));

        //1.统计学生有多少是湖北的
        List<Student123> list1 = list.stream()
                .filter(a -> a.getAddress() == "湖北")
                .collect(Collectors.toList());
        list1.forEach(System.out::println);
        System.out.println("************************");
        //2.将年龄大于18的同学找出来。不能光打印，需要存储下来
        List<Student123> list2 = list.stream()
                .filter(a -> a.getAge() > 18)
                .toList();
        list2.forEach(System.out::println);
        System.out.println("************************");
        //3.统计一下名字中包含 z 的且年龄大于18的,存储下来
        List<Student123> list3 = list.stream()
                .filter(a -> (a.getAge() > 18) && a.getName().contains("z"))
                .collect(Collectors.toList());
        list3.forEach(System.out::println);
    }
}

class Student123 {
    private int id;
    private String name;
    private String address;
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Student123(int id, String name, String address, int age) {
        this.id = id;
        this.name = name;
        this.address = address;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Student123() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student123 that = (Student123) o;
        return id == that.id && Objects.equals(name, that.name) && Objects.equals(address, that.address);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, address);
    }

    @Override
    public String toString() {
        return "Student123{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", age=" + age +
                '}';
    }
}

